/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Administrator
 */
public class Color implements TableInterface {

    private int cid;
    private int pid;
    private String colorum;
    private String colordesc;
    private boolean exist;

    /**
     * @return the cid
     */
    public int getCid() {
        return cid;
    }

    /**
     * @param cid the cid to set
     */
    public void setCid(int cid) {
        this.cid = cid;
    }

    /**
     * @return the pid
     */
    public int getPid() {
        return pid;
    }

    /**
     * @param pid the pid to set
     */
    public void setPid(int pid) {
        this.pid = pid;
    }

    /**
     * @return the colornum
     */
    public String getColornum() {
        return colorum;
    }

    /**
     * @param colornum the colornum to set
     */
    public void setColornum(String colornum) {
        this.colorum = colornum;
    }

    /**
     * @return the colordesc
     */
    public String getColordesc() {
        return colordesc;
    }

    /**
     * @param colordesc the colordesc to set
     */
    public void setColordesc(String colordesc) {
        this.colordesc = colordesc;
    }

    @Override
    public void insert(PreparedStatement pstmt) throws SQLException {
        pstmt.setInt(1, cid);
        pstmt.setInt(2, pid);
        pstmt.setString(3, colorum);
        pstmt.setString(4, colordesc);
        pstmt.setInt(5, 0);
        pstmt.executeUpdate();
        pstmt.close();
    }

    public Object getObject(ResultSet resultSet) throws SQLException {
        setExist(false);
        if (resultSet.next()) {
            this.setCid(resultSet.getInt("cid"));
            this.setPid(resultSet.getInt("pid"));
            this.setColornum(resultSet.getString("colornum"));
            this.setColordesc(resultSet.getString("colordesc"));
            setExist(true);
        }
        return this;
    }

    public String getTableName() {
        return "color";
    }

    public String getPrimaryKey() {
        return "cid";
    }

    public int getTableColumnCount() {
        return 5;
    }

    /**
     * @return the exist
     */
    public boolean isExist() {
        return exist;
    }

    /**
     * @param exist the exist to set
     */
    public void setExist(boolean exist) {
        this.exist = exist;
    }
}
